package com.ruoyi.system.mapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import com.ruoyi.system.domain.TbTask;
import com.ruoyi.system.domain.TbTaskDetail;
import com.ruoyi.system.domain.dto.AppActivityTrendDTO;
import com.ruoyi.system.domain.dto.TaskProgressDTO;
import com.ruoyi.system.domain.vo.*;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.core.parameters.P;

/**
 * 任务明细Mapper接口
 * 
 * @author ruoyi
 * @date 2025-07-23
 */
public interface TbTaskDetailMapper 
{
    /**
     * 查询任务明细
     * 
     * @param id 任务明细主键
     * @return 任务明细
     */
    public TbTaskDetail selectTbTaskDetailById(Long id);

    /**
     * 查询任务明细列表
     * 
     * @param tbTaskDetail 任务明细
     * @return 任务明细集合
     */
    public List<TbTaskDetailVO> selectTbTaskDetailList(TbTaskDetail tbTaskDetail);

    /**
     * 新增任务明细
     * 
     * @param tbTaskDetail 任务明细
     * @return 结果
     */
    public int insertTbTaskDetail(TbTaskDetail tbTaskDetail);

    /**
     * 修改任务明细
     * 
     * @param tbTaskDetail 任务明细
     * @return 结果
     */
    public int updateTbTaskDetail(TbTaskDetail tbTaskDetail);

    /**
     * 删除任务明细
     * 
     * @param id 任务明细主键
     * @return 结果
     */
    public int deleteTbTaskDetailById(Long id);

    /**
     * 批量删除任务明细
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTbTaskDetailByIds(Long[] ids);


    List<TbTaskDetail> selectTbTaskInfoListByTaskId(Long taskId);

    List<TbTaskDetail> selectTbTaskDetailListByPackageVersioncode(@Param("appName") String appName, @Param("packageVersionnumber") String appVersion,@Param("packageVersioncode") String packageVersioncode);

    int deleteTbTaskDetailByTaskIds( Long[] ids);

    int selectTaskDetailCountByTaskId(TbTask tbTask);

    int selectFailedDeviceCountByTaskId(Long taskId);

    Integer selectDetailCount(TbTaskVO statsQuery);


    List<AppActivityTrendDTO> selectTaskDetailCountByTaskType(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate,@Param("planeCode") String  planeCode);

    List<TaskProgressDTO> selectAppProgress(@Param("startTime") LocalDateTime startDateTime, @Param("endTime") LocalDateTime endDateTime,@Param("planeCode") String planeCode);

    List<TaskProgressDTO> selectPackageProgress(@Param("startTime") LocalDateTime startDateTime,@Param("endTime") LocalDateTime endDateTime);

    List<AppActivityStatsTaskFailInfoVO> getAppActivityStatsFailDeviceList(@Param("startTime") LocalDate startDate,@Param("endTime") LocalDate endDate,@Param("planeCode") String planeCode);

    List<TbTaskDetail> selectByTaskId(Long taskId);


    TaskStatistics selectTaskStatisticsByDevSn(String devSN);

    List<TaskExecutionResult> selectTaskResultsByDevSn(String devSN);

    List<TbTaskDetail> selectByDeviceId(Long deviceId);

    Integer countPendingTasksByDevSn(String devSN);

    List<PendingTask> selectPendingTasksByDevSn(String devSN);

    TbTaskDetail selectTbTaskDetailByCondition(@Param("taskId") Long taskId, @Param("packageVersioncode") String packageVersioncode, @Param("packageVersionnumber") String packageVersionnumber);

    List<TbTaskDetail> selectByTaskIds(@Param("detailIds") List<Long> detailIds);

    List<TbTaskDetail> selectByLastSuccessTaskIds(@Param("detailIds") List<Long> lastSuccessDetailIds);

    TbTaskDetail selectTbTaskDetailByIdAndStatus(@Param("taskDetailId") Long taskDetailId);

    TbTaskDetail findByTaskId(Long taskId);

    Double calculateOverallProgress(Long taskId);

    TbTaskDetail selectTbTaskDetailConditions(@Param("bundeleName") String bundeleName, @Param("appVersion") String appVersion, @Param("versionCode") String versionCode);

    TbTaskDetail selectByTaskIdAndAppInfo(@Param("taskId") Long taskId, @Param("bundeleName") String bundeleName
            , @Param("packageVersionnumber") String appVersion, @Param("packageVersioncode") String versionCode );

    TbTaskDetail selectByTaskIdAndPackageInfo(@Param("taskId") Long taskId, @Param("packageName") String bundeleName
            , @Param("packageVersionnumber") String appVersion, @Param("packageVersioncode") String versionCode);
}
